﻿@page "/ShowFolderSelectTest"
@inject IJSRuntime jsRuntime

<h3>ShowFolderSelectTest</h3>

<input type="file" id="folderPicker" webkitdirectory/>
<Button Text="Modal1" OnClick="Modal1Click" />
@code {

    public async Task Modal1Click()
    {
        //var value = await jsRuntime.InvokeAsync<string>("openFolderDialog");
    }

    public IJSObjectReference? module;

    protected override async Task OnInitializedAsync()
    {
        //module = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./FileDialog.js");
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await jsRuntime.InvokeVoidAsync("import", "./FileDialog.js");
        if (firstRender)
        {
            await jsRuntime.InvokeVoidAsync("eval", @"
         function getSelectedFolder() {
  const folderPicker = document.getElementById('folderPicker');
  const files = folderPicker.files;
  const output = document.getElementById('output');
 
  if (files.length > 0) {
    // 获取选中的第一个文件（文件夹）的WebkitRelativePath，即相对路径
    const fullPath = files[0].webkitRelativePath;
    output.textContent = '选择的文件夹路径: ' + fullPath;
  } else {
    output.textContent = '未选择文件夹';
  }
}
     ");

            // dotNetObjectReference = DotNetObjectReference.Create(this);
            // await jsRuntime.InvokeVoidAsync("initCanvas", dotNetObjectReference);
        }
    }
}
